package hot_100;

public class 无重复字符的最长子串 {
    public static void main(String[] args) {

    }

    public int lengthOfLongestSubstring(String s) {
        int[] nums = new int[26];
        char[] ss = s.toCharArray();
        int st = 0;
        int ans = 0;
        for (int ed = 0; ed < ss.length; ed++) {
            int num1 = ss[ed] - 'a';
            nums[num1]++;
            while (st < ed && nums[num1] >= 2) {
                int num2 = ss[st] - 'a';
                nums[num2]--;
                st++;
            }
            ans = Math.max(ans, ed - st + 1);
        }
        return ans;
    }
}
